import java.util.Arrays;
import java.util.Scanner;

public class 错误票据 {
    static int N = 10010;
    static int[] arr = new int[N];
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = Integer.parseInt(s.nextLine());
        int i=0;
        while(n-- >0) {
           String[] str = s.nextLine().split(" ");
           for (int j = 0; j < str.length ; j++) arr[i++] = Integer.parseInt(str[j]);
        }
        int[] cpy  = Arrays.copyOfRange(arr,0,i);

        Arrays.sort(cpy);
        int a = 0;
        int b = 0;
        for (int j = 0; j < cpy.length-1; j++) {
            if (cpy[j + 1] - cpy[j] == 2) a = cpy[j + 1] - 1;
            if(cpy[j+1] == cpy[j]) b = cpy[j];
        }
        System.out.println(a+" "+b);
    }
}
